package ljl.alg.jianzhioffer.round3.easy;

import java.util.LinkedList;

public class _30_MinStack {

    class MinStack {

        LinkedList<Integer> data = new LinkedList<>();
        LinkedList<Integer> min = new LinkedList<>();

        public void push(int x) {
            if (data.isEmpty()) {
                min.push(x);
            } else {
                min.push(Math.min(min.peek(), x));
            }
            data.push(x);
        }

        public void pop() {
            data.pop();
            min.pop();
        }

        public int top() {
            return data.peek();
        }

        public int min() {
            return min.peek();
        }
    }

}

